package com.kayo.specimen.utility;


import java.util.regex.Pattern;

public class PagingInfo {
    private int page;
    private int limit;
    private String sort;
    private String order;

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public PagingInfo() {
    }

    public PagingInfo(int page, int limit, String sort, String order) {
        this.page = page;
        this.limit = limit;
        this.sort = sort;
        this.order = order;
    }

    public String getOrderByClause(){
        if(StringUtils.isNullOrEmpty(sort)||StringUtils.isNullOrEmpty(order))
            return "1";

        if(Pattern.matches("\\d+",sort))
            return String.format("%s %s",sort,order);

        return String.format("`%s` %s",sort,order);
    }
}
